<script setup lang="ts">
import { ref } from "vue";
import { staticConfig } from "./utils/hook";
import { useRenderIcon } from "@/components/ReIcon/src/hooks";
import { PureTableBar } from "@/components/RePureTableBar";
import Refresh from "@iconify-icons/ep/refresh";
import EditPen from "@iconify-icons/ep/edit-pen";
import { usePublicFormats } from "../../../formats";

defineOptions({
  name: "staticParkConfig"
});

const formRef = ref();

const {
  columns,
  openDialog,
  form,
  loading,
  onSearch,
  resetForm,
  dataList,
  pagination,
  onSizeChange,
  onCurrentChange,
  loadingConfig
} = staticConfig();

//从父级钩子里取东西
const { statusOptions, paymentMethodOptions } = usePublicFormats();
</script>

<template>
  <div>
    <el-form
      ref="formRef"
      :inline="true"
      :model="form"
      class="search-form bg-bg_color w-[99/100] pl-8 pt-[12px]"
      :header-cell-style="{
        background: 'var(--el-fill-color-light)',
        color: 'var(--el-text-color-primary)'
      }"
    >
      <el-form-item label="推送url" prop="push_base_url">
        <el-input
          v-model="form.push_base_url"
          placeholder="请输入推送url"
          clearable
          class="!w-[160px]"
        />
      </el-form-item>
      <el-form-item label="Key" prop="access_key">
        <el-input
          v-model="form.access_key"
          placeholder="请输入Key"
          clearable
          class="!w-[160px]"
        />
      </el-form-item>
      <el-form-item label="密码" prop="access_password">
        <el-input
          v-model="form.access_password"
          placeholder="请输入密码"
          clearable
          class="!w-[160px]"
        />
      </el-form-item>
      <el-form-item label="商户id" prop="much_id">
        <el-input
          v-model="form.much_id"
          placeholder="请输入商户id"
          clearable
          class="!w-[160px]"
        />
      </el-form-item>
      <el-form-item label="余额" prop="money">
        <el-input
          v-model="form.money"
          placeholder="请输入余额"
          clearable
          class="!w-[160px]"
        />
      </el-form-item>
      <el-form-item label="状态：" prop="status">
        <el-select
          v-model="form.status"
          placeholder="请选择状态"
          clearable
          class="!w-[160px]"
        >
          <el-option
            v-for="item in statusOptions"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="支付类型" prop="payment_method">
        <el-select
          v-model="form.payment_method"
          placeholder="请选择状态"
          clearable
          class="!w-[160px]"
        >
          <el-option
            v-for="item in paymentMethodOptions"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          :icon="useRenderIcon('ri:search-line')"
          :loading="loading"
          @click="onSearch"
        >
          搜索
        </el-button>
        <el-button :icon="useRenderIcon(Refresh)" @click="resetForm(formRef)">
          重置
        </el-button>
      </el-form-item>
    </el-form>
    <PureTableBar title="静态停车" :columns="columns" @refresh="onSearch">
      <pure-table
        v-if="dataList.length > 0"
        ref="tableRef"
        row-key="id"
        alignWhole="center"
        showOverflowTooltip
        :loading="loading"
        :loading-config="loadingConfig"
        :columns="columns"
        :data="dataList"
        :header-cell-style="{
          background: 'var(--el-fill-color-light)',
          color: 'var(--el-text-color-primary)'
        }"
        :pagination="pagination"
        @page-size-change="onSizeChange"
        @page-current-change="onCurrentChange"
      >
        <template #operation="{ row }">
          <el-button
            class="reset-margin"
            link
            type="primary"
            :icon="useRenderIcon(EditPen)"
            @click="openDialog('修改', row)"
          >
            修改
          </el-button>
        </template>
      </pure-table>
    </PureTableBar>
  </div>
</template>
